package com.brillilab.starter.controller.aio.recycle;

import com.alibaba.fastjson.JSONObject;
import com.brillilab.common.entity.PageVo;
import com.brillilab.common.entity.ResponseVo;
import com.brillilab.domain.vo.kit.RecycleKitVo;
import com.brillilab.domain.vo.user.UserInfoVo;
import com.brillilab.service.core.kit.IKitService;
import com.brillilab.service.logic.recycle.RecycleLogic;
import com.brillilab.service.logic.user.UsersLogic;
import com.brillilab.starter.aspect.AspectLog;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;

/**
 * 回收站
 *
 * @author wmh
 */
@RestController
@RequestMapping("/api/recycle")
public class RecycleController {

    @Autowired
    private RecycleLogic recycleLogic;
    @Autowired
    private UsersLogic usersLogic;


    /**
     * 删除试剂列表
     * @return
     */
    @RequestMapping(value="/kit/list",method=RequestMethod.GET)
    public ResponseVo kitList(Integer pageNum,Integer pageSize,@RequestHeader String token){

        Assert.isTrue(pageNum!=null && pageSize!=null,"请求参数缺失！");

        UserInfoVo userInfo=usersLogic.getUserByToken(token);

        PageVo<RecycleKitVo> recycleKitVoPageVo=recycleLogic.getKitRecyclePage(pageNum,pageSize,userInfo.getLabId());

        return ResponseVo.success(recycleKitVoPageVo);
    }

    /**
     * 恢复删除的试剂
     * @param jsonObject
     * @return
     */
    @AspectLog
    @RequestMapping(value="/kit/recovery",method=RequestMethod.POST)
    public ResponseVo kitRecovery(@RequestBody JSONObject jsonObject,@RequestHeader String token){

        Long kitId=jsonObject.getLong("kitId");
        Assert.notNull(kitId,"请求参数缺失！");

        UserInfoVo userInfo=usersLogic.getUserByToken(token);

        boolean rs = recycleLogic.kitRecovery(userInfo.getLabId(),kitId);
        if(rs){
            return ResponseVo.success();
        }
        return ResponseVo.failure();
    }

}
